<?php


namespace app\home\services;

use app\admin\model\MessageModel;

class MessageService
{
    private $model;

    public function __construct()
    {
        $this->model = new MessageModel();
    }

    public function getList($param = [], $field = [])
    {
        if (!isset($param['page']) || $param['page'] <= 0) {
            $param['page'] = 1;
        }
        if (!isset($param['pageSize']) || $param['pageSize'] <= 0) {
            $param['pageSize'] = 5;
        }
        $list = $this->model->field($field)->limit(($param['page'] - 1) * $param['pageSize'], $param['pageSize'])->select();
        foreach ($list as &$item) {
            $item['create_time'] = date("Y-m-d H:i", $item['create_time']);
        }
        return $list;
    }

    public function getInfoById($id){
        $info = $this->model->where([
            'id' => $id,
            'status' => 1,
            'is_delete' => 1
        ])->find();
        return $info;
    }

}